<template>
	<BaseContainer>
		<aplid-base-crud ref="crud" class="w-100" v-bind="{...baseConfig,...$attrs}" :paramsObj="$attrs.paramsObj||baseConfig.paramsObj" :operateFormate="operateFormate">
			<template v-slot:designDialog="{ row, show }">
				<FormDesign hideField="ueditor" :showHeader="false" v-if="show" :templateId="row.id" :nowRowData="row" :templateNo="row.templateNo" @refresh="handleRefresh">
				</FormDesign>
			</template>
		</aplid-base-crud>
	</BaseContainer>
</template>

<script setup>
import { baseConfig } from './config'
import FormDesign from '@/views/aplid/FormDesign/index.vue'
import { useDesign } from '@/stores/design'
import apiMod from '@/apiMod/index'

const { setDesignData } = useDesign()

const crud = ref(null)
const handleRefresh = (query, visible = false) => {
	nextTick(() => {
		crud.value.refreshChange(query)
	})
}

const operateFormate = (params, type) => {
	return new Promise((resolve, reject) => {
		if (type == 'design') {
			apiMod.view_tableTemplate_id(params.id).then((res) => {
				const list = res.data?.jsonStr?.column.map((item) => {
					return {
						option: item,
					}
				})
				setDesignData(list||[])
        resolve(params)
			})
		} else {
			resolve(params)
		}
	})
}
</script>

<style lang="scss" scoped></style>
